/**
 * @author ChaP
 * @date 2019/04/13
 * @describe:
 */
package CodingTest.AC20190412;

/**
 * 编写一个函数，以字符串作为输入，反转该字符串中的元音字母。

 示例 1:

 输入: "hello"
 输出: "holle"
 示例 2:

 输入: "leetcode"
 输出: "leotcede"
 说明:
 元音字母不包含字母"y"。

 a,e,i,o,u
 */
public class reverseVowels {
    public String reverseVowels(String s){
        int start = 0;
        int end = s.length()-1;
        char[] ch = s.toCharArray();
        while(start < end){
            while(!helper(ch[start]) && start<end){
                ++start;}
            while(!helper(ch[end]) && start < end){
                --end;}
            char temp = ch[start];
            ch[start++] = ch[end];
            ch[end--] = temp;

        }
        String result = String.valueOf(ch);
        return result;
    }
    public boolean helper(char res){
        if(res=='a' ||res =='e' || res =='i' || res == 'o' || res == 'u'||
                res == 'A' ||res =='E' ||res =='I' ||res =='O' ||res =='U'){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        reverseVowels rv = new reverseVowels();
        System.out.println(rv.reverseVowels("hello"));
    }
}
